#!/usr/bin/env python
import urllib2
from xml.dom.minidom import parseString

BNBurl = "http://www.bnb.bg/Statistics/StExternalSector/StExchangeRates/StERForeignCurrencies/index.htm?download=xml&search=&lang=BG"

LOOKING_FOR = ['USD', 'EUR', 'CHF']

if __name__ == "__main__":
    f = urllib2.urlopen(BNBurl)
    xml = f.read()
    dom = parseString(xml)
    top = dom.documentElement
    for r in top.getElementsByTagName('ROW'):
        c = r.getElementsByTagName('CODE')[0].childNodes[0].data
        if c in LOOKING_FOR:
            v = r.getElementsByTagName('RATE')[0].childNodes[0].data
            rv = r.getElementsByTagName('REVERSERATE')[0].childNodes[0].data
            print "%s : %s / %s" % (c, v, rv)
